package com.xspace.android.xafcommon.util;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.xspace.android.xafcommon.R;


/**
 * Created by liuchen on 2016/11/15.
 */
public class HeadShowUtil {

    private static final String TAG = HeadShowUtil.class.getSimpleName();

    public enum HeadType {
        UserLogo,
        OrgLogo,
        WnxLogo
    }

    public enum Sex {
        Man("男", "1"),
        Woman("女", "2");
        private String txt;
        private String number;

        Sex(String sex, String number) {
            txt = sex;
            this.number = number;
        }

        public String getNumber() {
            return number;
        }

        public String getTxt() {
            return txt;
        }
    }

    public static void headShow(Context mContext, String remoteUrl, String sex, View showView, HeadType type) {
        if (showView instanceof ImageView) {
            ImageView imageView = (ImageView) showView;
            int defaultHeadId = R.drawable.bg_default_wnx;
            if (type == HeadType.UserLogo) {
                defaultHeadId = R.drawable.icon_header_default;
                if ((Sex.Woman.getNumber()).equals(sex) || Sex.Woman.getTxt().equals(sex)) {
                    defaultHeadId = R.drawable.icon_header_default_woman;
                }
            } else if (type == HeadType.OrgLogo) {
                defaultHeadId = R.drawable.icon_org_logo_default;
            } else if (type == HeadType.WnxLogo) {
                defaultHeadId = R.drawable.bg_default_wnx;
            }
            if (TextUtils.isEmpty(remoteUrl)) {
                imageView.setImageResource(defaultHeadId);
            } else {
                Picasso.with(mContext)
                        .load(remoteUrl)
                        .placeholder(defaultHeadId)
                        .error(defaultHeadId)
                        .into(imageView);
            }
        }
    }
}
